﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;

namespace lcmyjobs.Web.hunter
{
    public partial class hadvlist : BasePage
    {
        lcmyjobs.BLL.user_adv bub = new BLL.user_adv();
        DataSet ds;
        int count = 0;
        int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            id = int.Parse(Application["webid"].ToString());
            if (!IsPostBack)
            {
                txtjob.Attributes.Add("readonly", "true");
                txttrade.Attributes.Add("readonly", "true");
                txtarea.Attributes.Add("readonly", "true");
                txthuji.Attributes.Add("readonly", "true");
                this.Title = string.Format("中高端人才--{1}猎头 {1}猎头公司 聊城猎头 聊城猎头公司 {0}", Application["webname"].ToString(), Application["webregion"].ToString());
                //getcout(id);
                
                bind(id);
                //bindData(); //使用url分页，只需在分页事件处理程序中绑定数据即可，无需在Page_Load中绑定，否则会导致数据被绑定两次
            }


        }
        protected void getcout(int atid)
        {
            ds = bub.PageUserAdvHunter(atid, 1, AspNetPager1.PageSize, out count);
            AspNetPager1.RecordCount = count;
            //GridView1.DataSource = ds.Tables[0];
            //GridView1.DataBind();

        }
        protected void bind(int atid)
        {
            ds = bub.PageUserAdvHunter(atid, AspNetPager1.StartRecordIndex, AspNetPager1.PageSize, out count);
            AspNetPager1.RecordCount = count;
            //GridView1.DataSource = ds.Tables[0];
            //GridView1.DataBind();
            if(AspNetPager1.RecordCount>AspNetPager1.PageSize){
                AspNetPager1.Visible = true;
                lbl_fenye.Visible = true;
            }
            else{
                AspNetPager1.Visible = false;
                lbl_fenye.Visible = false;
            }
            StringBuilder str = new StringBuilder("<ul>");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                DataRow row = ds.Tables[0].Rows[i];
                setGdjc(str, row);
            }
            str.Append("</ul>");
            this.ltr_gdrc.Text = str.ToString();
        }

        private void setGdjc(StringBuilder str, DataRow row)
        {
            str.Append("<li class='elite'>");
            str.Append("<a target='_blank' href='show_user-");
            str.Append(row["abh"]);
            str.Append(".html' title='");
            str.Append(row["jobs"]);
            str.Append("'>");
            str.Append("<h3>求职意向：");
            str.Append(row["jobs"]);
            str.Append("</h3>");
            str.Append("<ul class='clear_fix'>");
            str.Append("<li class='no'><span>编号：</span>L");
            str.Append(row["abh"].ToString().PadLeft(6, '0'));
            str.Append("</li>");
            str.Append("<li class='xueli'><span>学历：</span>");
            str.Append(GetStrSub(row["edu_name"].ToString(),8));
            str.Append("</li>");
            str.Append("<li class='jobtime'><span>工作经验：</span>");
            str.Append(GetStrSub(row["workexpname"].ToString(),8));
            str.Append("</li>");
            str.Append("<li class='city'><span>地点：</span>");
            str.Append(GetStrSub(row["areas"].ToString(), 8));
            str.Append("</li>");
            str.Append("<li class='timestamp'><span>注册时间：</span>");
            str.Append(row["wantedtime"].ToString().Substring(0, 10));
            str.Append("</li>");
            str.Append("<li class='salary'>期望年薪：<strong class='orange'>");
            str.Append(row["yearpay"].ToString());
            str.Append("万</strong></li></ul>");
            str.Append("</a></li>");
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            id = int.Parse(Application["webid"].ToString());
            bind(id);

        }



        protected void btnSearch_Click(object sender, EventArgs e)
        {

            lcmyjobs.Model.searchCondition sc = GetModel();
            bindsearch(AspNetPager1.StartRecordIndex, 20, sc);
        }

        private lcmyjobs.Model.searchCondition GetModel()
        {
            lcmyjobs.Model.searchCondition sc = new Model.searchCondition();            
            sc.jobs = txtjob.Text.Trim();
            sc.area = txtarea.Text.Trim();
            sc.trade = txttrade.Text.Trim();
            sc.huji = txthuji.Text.Trim();
            sc.exp =int.Parse( ddlExp.SelectedValue.ToString());
            int min = 0, max = 0,amin=0,amax=0;            
            if (txtYmin.Text.Trim() != "")
                min = int.Parse(txtYmin.Text.Trim());
            if (txtYmax.Text.Trim() != "")
                max = int.Parse(txtYmax.Text.Trim());
            if (txtAmin.Text.Trim() != "")
                amin = int.Parse(txtAmin.Text.Trim());
            if (txtAmax.Text.Trim() != "")
                amax = int.Parse(txtAmax.Text.Trim());
            sc.agemax = amax;
            sc.agemin = amin;
            sc.salaryymax = max;
            sc.salaryymin = min;
            sc.keyword = txt_keywords.Text.Trim();
            
            return sc;
        }
        private string GetStrSub(string str, int length)
        {
            if (str.Length > length)
            {
                //return str.Substring(0, length) + "...";
                return str.Substring(0, length);
            }
            else
            {
                return str;
            }
        }

        protected void bindsearch(int start, int endindex, lcmyjobs.Model.searchCondition sc)
        {
            SqlParameter[] parameters = {			 
			 			 new SqlParameter("@job_name1", SqlDbType.NVarChar,20),     //0
                          new SqlParameter("@job_name2", SqlDbType.NVarChar,20),    //1
                          new SqlParameter("@job_name3", SqlDbType.NVarChar,20),    //2                         
                          new SqlParameter("@exp", SqlDbType.Int,4),                //7                         
                         new SqlParameter("@areas1", SqlDbType.NVarChar,20),        //9
			 			 new SqlParameter("@areas2", SqlDbType.NVarChar,20),        //10
			 			 new SqlParameter("@areas3", SqlDbType.NVarChar,20),        //11
			 			 new SqlParameter("@trades1", SqlDbType.NVarChar,20),       //12
			 			 new SqlParameter("@trades2", SqlDbType.NVarChar,20),       //13
			 			 new SqlParameter("@trades3", SqlDbType.NVarChar,20),       //14			 			
			 			 new SqlParameter("@startIndex", SqlDbType.Int,4),          //22
			 			 new SqlParameter("@endIndex", SqlDbType.Int,4),            //23
			 			new SqlParameter("@keyword",SqlDbType.NVarChar,20),         //24
			 			 new SqlParameter("@count", SqlDbType.Int,4),               //25
                          
                new SqlParameter("@salaryymin",SqlDbType.Int),       
                new SqlParameter("@salaryymax",SqlDbType.Int), 
                 new SqlParameter("@huji",SqlDbType.NVarChar,20),
                new SqlParameter("@agemin",SqlDbType.Int),       
                new SqlParameter("@agemax",SqlDbType.Int) 			 			    
			 			 };
            string[] a;
            if (sc.jobs != "")
            {
                a = sc.jobs.Split(',');
                if (a.Length > 0)
                    parameters[0].Value = a[0];
                if (a.Length > 1)
                    parameters[1].Value = a[1];
                if (a.Length > 2)
                    parameters[2].Value = a[2];
            }           
            parameters[3].Value = sc.exp;                 
            if (sc.area != "")
            {
                a = sc.area.Split(',');
                if (a.Length > 0)
                    parameters[4].Value = a[0];
                if (a.Length > 1)
                    parameters[5].Value = a[1];
                if (a.Length > 2)
                    parameters[6].Value = a[2];
            }
            if (sc.trade != "")
            {
                a = sc.trade.Split(',');
                if (a.Length > 0)
                    parameters[7].Value = a[0];
                if (a.Length > 1)
                    parameters[8].Value = a[1];
                if (a.Length > 2)
                    parameters[9].Value = a[2];
            }
           
           
            parameters[10].Value = start;
            parameters[11].Value = endindex;
            parameters[12].Value = sc.keyword;
            parameters[13].Direction = ParameterDirection.Output;
            parameters[14].Value = sc.salaryymin;
                parameters[15].Value = sc.salaryymax;
                parameters[16].Value = sc.huji;
                parameters[17].Value = sc.agemin;
                parameters[18].Value = sc.agemax;

            lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
            DataSet ds = bub.PageUserSearch(parameters,1);
            AspNetPager1.RecordCount = int.Parse(parameters[13].Value.ToString());

            int cnt = ds.Tables[0].Rows.Count;


            if (this.AspNetPager1.RecordCount > this.AspNetPager1.PageSize)
            {
                this.AspNetPager1.Visible = true;
                lbl_fenye.Visible = true;
            }
            else
            {
                this.AspNetPager1.Visible = false;
                lbl_fenye.Visible = false;
            }

            StringBuilder str = new StringBuilder("<ul>");
            for (int i = 0; i < cnt; i++)
            {
                DataRow row = ds.Tables[0].Rows[i];
                setGdjc(str, row);
            }
            str.Append("</ul>");
            this.ltr_gdrc.Text = str.ToString();

        }
    }
}